home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / INTERPE.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  54 lines

  1. ############################################################################
  2. #
  3. #    File:     interpe.icn
  4. #
  5. #    Subject:  Program to interpret Icon expressions
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 30, 1991
  10. #
  11. ###########################################################################
  12. #
  13. #    This program is a crude but effective interpreter for Icon expressions.
  14. #  Each line entered from standard input is presumed to be an Icon
  15. #  expression, is wrapped with a main procedure, and written to a pipe
  16. #  that compiles and executes the resulting program.
  17. #
  18. #    If the expression is a generator, all its results are produced.
  19. #  If the command-line option -e is given, the expression is echoed.
  20. #
  21. #    This technique is, of course, inefficient and may be painfully
  22. #  slow except on the fastest platforms. This technique is, however,
  23. #  completely general and as correct as Icon itself.
  24. #
  25. #    Note:  This programs creates files with the names stdin, stdin.u1,
  26. #  and stdin.u2. It removes them before terminating, but, of course,
  27. #  overwrites any pre-existing files by these names.
  28. #
  29. ############################################################################
  30. #
  31. #  Requires: UNIX
  32. #
  33. #  See also:  interpp.icn
  34. #
  35. ############################################################################
  36.  
  37. procedure main(args)
  38.    local line, run, echo
  39.  
  40.    if args[1] == "-e" then echo := 1
  41.  
  42.    while line := read() do {
  43.       run := open("icont -s - -x","pw")
  44.       write(run,"procedure main()")
  45.       if \echo then write(run,"   write(",image(line),")")
  46.       write(run,"   every write(image(",line,"))")
  47.       write(run,"end")
  48.       close(run)
  49.       }
  50.  
  51.    system("rm -f stdin stdin.u1 stdin.u2")
  52.  
  53. end
  54.